const mongoose=require("mongoose");
mongoose.connect("mongodb://127.0.0.1:27017/test");

const tagSchema=new mongoose.Schema({
    // text:String,
    text:{
        type:String,
        minlength:2,
        maxlength:12
    }
})
const userSchema=new mongoose.Schema({
    username:{
        type:String,
        minlength:2,
        maxlength:[12,"用户名最多12个字符"]
    },
    password:{
        type:String,
        validate:{//验证
            validator: function(v) {//验证器
                return /[a-zA-Z0-9_]{6,12}/.test(v);
            },
            message: "密码只能是6-12位的数字、字母、下划线的任意组合"
        }
    },
    email: {
        type: String,
        validate: {
          validator: function(v) {
            return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(v);//  /\w+@\w+\.\w-/
          },
          message: '{VALUE} is not a valid phone number!'
        },
        required: [true, '邮箱格式不正确']
    },
    arr:{
        type:String,
        enum:{
            values:['限制会员','新手上路','组册会员','中级会员','高级会员'],
            message:"{value} is not supported"
        }
    }
})
const contentSchema=new mongoose.Schema({
    title:{
        type:String,
        minlength:6,
        maxlength:12
    },
    content:{
        type:String,
        minlength:10,
        maxlength:50
    },
    top:{
        type:Boolean,
        default:false
    }
})
const tagModel=new mongoose.model("tag",tagSchema);
const userModel=new mongoose.model("user",userSchema);
const contentModel=new mongoose.model("content",contentSchema);
//tagModel

module.exports={tagModel,userModel,contentModel};

// const arr=[{text:"HTML"},{text:"SQL"},{text:"Nodejs"}];
// tagModel.insertMany(arr,function (err, docs) {
//     console.log(err);
//     console.log(docs);
// });